package com.charger.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.charger.domain.QCharger;
import com.charger.domain.QChargerStation;
import com.charger.mapper.QChargerMapper;
import com.charger.mapper.QChargerStationMapper;
import com.charger.service.QChargerStationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @ClassName QChargerStationServiceImpl
 * @Description TODO
 * @Author QinKunPeng
 * @Date 2024年11月26日 9:25
 * @Version 1.0
 */
@Service
@Transactional
public class QChargerStationServiceImpl extends ServiceImpl<QChargerStationMapper, QChargerStation> implements QChargerStationService {

    @Autowired
    QChargerMapper qChargerMapper;

    public List<QChargerStation> getChargerStations(){
        List<QChargerStation> list = this.list();
        list.forEach(chargerstation -> {
//            QChargerStation qChargerStation = qChargerStationMapper.selectById(1);
            if (chargerstation != null){
                QueryWrapper<QCharger> q = new QueryWrapper<>();
                q.eq("chargingStation_id", chargerstation.getId());
                List<QCharger> qChargers = qChargerMapper.selectList(q);
                chargerstation.setChargers(qChargers);
//                System.out.println(chargerstation);
            }
        });
        return list;
    }
}
